package cn.sc.summer.adapter.controller;

import cn.sc.summer.constant.model.Result;
import cn.sc.summer.domain.sms.SmsTemplateService;
import cn.sc.summer.protocol.form.sms.SmsTemplateAddForm;
import cn.sc.summer.protocol.vo.SmsTemplateVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类名：短信模版配置项
 *
 * @author a-xin
 * @date 2023/12/15 16:24
 */
@Slf4j
@RestController
@RequestMapping("/sms")
@Api(tags = "sms-短信模版管理")
public class SmsTemplateController {

    @Resource
    private SmsTemplateService smsTemplateService;

    @GetMapping("/getTemplate")
    @ApiOperation(value = "获取短信模版信息")
    public Result<List<SmsTemplateVO>> getTemplate(@RequestParam(value = "server", required = false) String server) {
        return Result.success(smsTemplateService.getTemplate(server));
    }

    @PostMapping("/addTemplate")
    @ApiOperation(value = "添加短信模版")
    public Result<SmsTemplateVO> addTemplate(@Validated @RequestBody SmsTemplateAddForm form) {
        return Result.success(smsTemplateService.addTemplate(form));
    }

    @GetMapping("/deleteTemplate")
    @ApiOperation(value = "删除短信模板")
    public Result<String> deleteTemplate(@RequestParam("id") String id) {
        smsTemplateService.deleteTemplate(id);
        return Result.success();
    }

}
